<style lang="less">
    @import "../../../../styles/table.less";
</style>
<template>
    <div class="search">
        <Row>
            <Col>
                <Card title="学员报考资料">
                    <Row @keydown.enter.native="handleSearch">
                        <Form ref="searchForm" :model="searchForm" inline :label-width="70">
                            <Form-item label="学员姓名" prop="userName">
                                <Input type="text" v-model="searchForm.userName" placeholder="请输入学员姓名" clearable style="width: 200px"/>
                            </Form-item>
                            <Form-item label="手机号" prop="mobile">
                                <Input type="text" v-model="searchForm.mobile" placeholder="请输入手机号" clearable style="width: 200px"/>
                            </Form-item>
                            <Form-item style="margin-left:-35px;" class="br">
                                <Button @click="handleSearch" type="primary" icon="ios-search">搜索</Button>
                                <Button @click="handleReset">重置</Button>
                                <a class="drop-down" @click="dropDown">{{dropDownContent}}
                                    <Icon :type="dropDownIcon"></Icon>
                                </a>
                            </Form-item>
                        </Form>
                    </Row>
                    <Row>
                        <Table :loading="loading" border :columns="columns" :data="data" sortable="custom" @on-sort-change="changeSort" @on-selection-change="showSelect" ref="table"></Table>
                    </Row>
                    <Row type="flex" justify="end" class="page">
                        <Page :current="searchForm.pageNumber" :total="total" :page-size="searchForm.pageSize" @on-change="changePage" @on-page-size-change="changePageSize" :page-size-opts="[10,20,50]" size="small" show-total show-elevator show-sizer></Page>
                    </Row>
                </Card>
            </Col>
        </Row>
        <Modal v-model="picVisible" :title="title" draggable>
            <img :src="fileUrl" alt="无效的图片链接" style="width: 100%;margin: 0 auto;display: block;">
        </Modal>
        <eduManage ref="educationManage"></eduManage>
        <workManage ref="workManage"></workManage>
        <trainManage ref="trainManage"></trainManage>
        <certificateManage ref="certificateManage"></certificateManage>
    </div>
</template>

<script>
    import {studentList2} from "@/api/bus";
    import eduManage from "./eduManage";
    import workManage from "./workManage";
    import trainManage from "./trainManage";
    import certificateManage from "./certificateManage";
    import circleLoading from "../../../my-components/circle-loading.vue";

    export default {
        name: "student-manage",
        components: {
            circleLoading,
            eduManage,
            workManage,
            trainManage,
            certificateManage
        },
        data() {
            return {
                loading: false, // 表单加载状态
                operationLoading: false,
                drop: false,
                selectCount: 0, // 多选计数
                selectList: [], // 多选数据
                dropDownContent: "展开",
                dropDownIcon: "ios-arrow-down",
                searchForm: {
                    pageNumber: 1, // 当前页数
                    pageSize: 10, // 页面大小
                    sort: "createTime", // 默认排序字段
                    order: "desc", // 默认排序方式
                    userName: "",
                    company: "",
                    userType: "UT_STUDENT",
                    mobile: "",
                    startDate: "",
                    endDate: ""
                },
                selectDate: null, //选择日期绑定modal
                columns: [
                    {
                        type: "index",
                        width: 60,
                        fixed: "left",
                        align: "center"
                    },
                    {
                        title: "头像",
                        key: "avatar",
                        width: 80,
                        fixed: "left",
                        align: "center",
                        render: (h, params) => {
                            if(params.row.avatar){
                                return h("Avatar", {
                                    props: {
                                        src: params.row.avatar
                                    }
                                });
                            }else{
                                return h("Avatar", {
                                    props: {
                                        src: "https://s1.ax1x.com/2018/05/19/CcdVQP.png"
                                    }
                                });
                            }
                        }
                    },
                    {
                        title: "学员姓名",
                        key: "userName",
                        fixed: "left",
                        width: 150,
                        align: "center"
                    },
                    {
                        title: "昵称",
                        key: "nickName",
                        width: 150,
                        align: "center"
                    },
                    {
                        title: "手机",
                        key: "mobile",
                        width: 115,
                        align: "center"
                    },
                    {
                        title: "性别",
                        key: "sex",
                        width: 70,
                        align: "center",
                        render: (h, params) => {
                            let re = "";
                            if (params.row.sex === 2) {
                                re = "男";
                            } else if (params.row.sex === 1) {
                                re = "女";
                            } else {
                                re = "--";
                            }
                            return h("div", re);
                        }
                    },
                    {
                        title: "邮箱",
                        key: "email",
                        width: 160,
                        align: "center"
                    },
                    {
                        title: "国籍",
                        key: "nationality",
                        width: 100,
                        align: "center"
                    },
                    {
                        title: "民族",
                        key: "nation",
                        width: 100,
                        align: "center"
                    },
                    {
                        title: "联系地址",
                        key: "cityString",
                        width: 160,
                        align: "center"
                    },
                    {
                        title: "详细地址",
                        key: "address",
                        width: 160,
                        align: "center"
                    },
                    {
                        title: "身份证号",
                        key: "idCard",
                        width: 180,
                        align: "center"
                    },
                    {
                        title: "学习中心",
                        key: "learnCenter",
                        width: 150,
                        align: "center"
                    },
                    {
                        title: "身份认证",
                        key: "licenseStatus",
                        align: "center",
                        width: 130,
                        render: (h, params) => {
                            let re = "";
                            if (params.row.licenseStatus == 0) {
                                return h("div", [
                                    h(
                                        "Tag",
                                        {
                                            props: {
                                                color: "#48CFFA"
                                            }
                                        },
                                        "未识别"
                                    )
                                ]);
                            } else if (params.row.licenseStatus == 1) {
                                return h("div", [
                                    h(
                                        "Tag",
                                        {
                                            props: {
                                                color: "#32FA4B"
                                            }
                                        },
                                        "识别通过"
                                    )
                                ]);
                            } else if (params.row.licenseStatus == 2){
                                return h("div", [
                                    h(
                                        "Tag",
                                        {
                                            props: {
                                                color: "#FA1031"
                                            }
                                        },
                                        "识别未通过"
                                    )
                                ]);
                            } else {
                                return h("div", "--");
                            }
                        }
                    },
                    {
                        title: "身份证正面",
                        key: "cardNoImg",
                        width: 120,
                        align: "center",
                        render: (h, params) => {
                            if(params.row.cardNoImg){
                                return h("img", {
                                    attrs: {
                                        src: params.row.cardNoImg,
                                        alt: "加载图片失败"
                                    },
                                    style: {
                                        cursor: "pointer",
                                        width: "80px",
                                        height: "60px",
                                        margin: "3px 0",
                                        "object-fit": "contain"
                                    },
                                    on: {
                                        click: () => {
                                            this.showPic(params.row.cardNoImg, '身份证正面');
                                        }
                                    }
                                });
                            }else{
                                return h("div", '--');
                            }


                        }
                    },
                    {
                        title: "身份证反面",
                        key: "cardNoImg2",
                        width: 120,
                        align: "center",
                        render: (h, params) => {
                            if(params.row.cardNoImg2){
                                return h("img", {
                                    attrs: {
                                        src: params.row.cardNoImg2,
                                        alt: "加载图片失败"
                                    },
                                    style: {
                                        cursor: "pointer",
                                        width: "80px",
                                        height: "60px",
                                        margin: "3px 0",
                                        "object-fit": "contain"
                                    },
                                    on: {
                                        click: () => {
                                            this.showPic(params.row.cardNoImg2, '身份证反面');
                                        }
                                    }
                                });
                            }else{
                                return h("div", '--');
                            }


                        }
                    },
                    {
                        title: "正面照",
                        key: "cardLiveImg",
                        width: 120,
                        align: "center",
                        render: (h, params) => {
                            if(params.row.cardLiveImg){
                                return h("img", {
                                    attrs: {
                                        src: params.row.cardLiveImg,
                                        alt: "加载图片失败"
                                    },
                                    style: {
                                        cursor: "pointer",
                                        width: "80px",
                                        height: "60px",
                                        margin: "3px 0",
                                        "object-fit": "contain"
                                    },
                                    on: {
                                        click: () => {
                                            this.showPic(params.row.cardLiveImg, '正面照');
                                        }
                                    }
                                });
                            }else{
                                return h("div", '--');
                            }
                        }
                    },
                    {
                        title: "国开学籍号",
                        key: "schoolNum",
                        width: 130,
                        align: "center"
                    },
                    {
                        title: "操作",
                        key: "action",
                        width: 200,
                        fixed: "right",
                        align: "center",
                        render: (h, params) => {
                            return h("div", [
                                h(
                                    "Button",
                                    {
                                        props: {
                                            type: "primary",
                                            size: "small"
                                        },
                                        style: {
                                            marginRight: "5px"
                                        },
                                        on: {
                                            click: () => {
                                                this.education(params.row);
                                            }
                                        }
                                    },
                                    "教育经历"
                                ),
                                h(
                                    "Dropdown",
                                    {
                                        props: {transfer: true},
                                        style: {
                                            marginLeft: "5px"
                                        },
                                        on: {
                                            "on-click": v => {
                                                this.changeDropDown(params.row, v);
                                            }
                                        }
                                    },
                                    [
                                        h(
                                            "Button",
                                            {
                                                props: {size: "small"},
                                                style: {
                                                    height: "23.5px"
                                                }
                                            },
                                            "更多操作 ∨"
                                        ),
                                        h("DropdownMenu", {slot: "list"}, [
                                            h("DropdownItem", {props: {name: "work"}}, "工作经历"),
                                            h("DropdownItem", {props: {name: "train"}}, "培训经历"),
                                            h("DropdownItem", {props: {name: "certificate"}}, "登记证书")
                                        ])
                                    ]
                                )
                            ]);
                        }
                    }],
                data: [], // 表单数据
                total: 0, // 表单数据总数
                title: '身份证正面',
                fileUrl: '',
                picVisible: false
            }
        },
        methods: {
            init() {
                this.getDataList();
            },
            changeDropDown(row, v) {
                if (v == "work") {
                    this.work(row);
                }
                if (v == "train") {
                    this.train(row);
                }
                if (v == "certificate") {
                    this.certificate(row);
                }
            },
            showPic(v, imgName) {
                this.title = imgName
                this.fileUrl = v;
                this.picVisible = true;
            },
            education(v) {
                this.$refs.educationManage.showDrawer(v.id);
            },
            work(v) {
                this.$refs.workManage.showDrawer(v.id);
            },
            train(v) {
                this.$refs.trainManage.showDrawer(v.id);
            },
            certificate(v) {
                this.$refs.certificateManage.showDrawer(v.id);
            },
            getDataList() {
                // 多条件搜索用户列表
                this.loading = true;
                studentList2(this.searchForm).then(res => {
                    this.loading = false;
                    if (res.status === true) {
                        this.data = res.data.rows;
                        this.total = res.data.total;
                    }
                });
            },
            handleSearch() {
                this.searchForm.pageNumber = 1;
                this.searchForm.pageSize = 10;
                this.getDataList();
            },
            handleReset() {
                this.$refs.searchForm.resetFields();
                this.searchForm.pageNumber = 1;
                this.searchForm.pageSize = 10;
                this.selectDate = null;
                this.username = "";
                this.mobile = "";
                this.company = "";
                this.searchForm.startDate = "";
                this.searchForm.endDate = "";
                // 重新加载数据
                this.getDataList();
            },
            dropDown() {
                if (this.drop) {
                    this.dropDownContent = "展开";
                    this.dropDownIcon = "ios-arrow-down";
                } else {
                    this.dropDownContent = "收起";
                    this.dropDownIcon = "ios-arrow-up";
                }
                this.drop = !this.drop;
            },
            changePage(v) {
                this.searchForm.pageNumber = v;
                this.getDataList();
            },
            changePageSize(v) {
                this.searchForm.pageSize = v;
                this.getDataList();
            },
            changeSort(e) {
                this.searchForm.sort = e.key;
                this.searchForm.order = e.order;
                if (e.order === "normal") {
                    this.searchForm.order = "";
                }
                this.getDataList();
            },
            showSelect(e) {
                this.selectList = e;
                this.selectCount = e.length;
            },
        },
        mounted() {
            this.init();
        }
    }
</script>
